package com.hackintosh.simple;

/**
 * @description：
 * @author：twislyn
 * @date：Created in 2021/06/06
 * @modified By：
 * @version: 1.0
 */
public class MementoPattern {

    public static void main(String[] args) {
        Originator originator = new Originator("Q1");
        System.out.println("初始状态：" + originator.getState());
        CareTaker careTaker = new CareTaker();
        // 保存状态
        careTaker.setMemento(originator.createMemento());

        originator.setState("Q2");
        System.out.println("新的状态：" + originator.getState());
        originator.restoreMemento(careTaker.getMemento());
        System.out.println("恢复状态：" + originator.getState());

    }
}
